home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -seriously_amiga- / shareware / programming / other / pmdev / demos / pulldownmenu.c < prev    next >
C/C++ Source or Header  |  1998-01-05  |  5KB  |  179 lines

  1. //
  2. // $VER: TestMenu.c 2.0 (11.10.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/alib_protos.h>
  18.  
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include <libraries/pm.h>
  24. #include <proto/pm.h>
  25.  
  26. struct IntuitionBase    *IntuitionBase;
  27. struct GfxBase        *GfxBase;
  28. struct PopupMenuBase    *PopupMenuBase;
  29.  
  30. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  31.             // The font in this window's rastport will be used for the menu.
  32.  
  33. ULONG __saveds __asm MenuHandlerFunc(register __a0 struct Hook *hook,
  34.                      register __a2 APTR object,
  35.                      register __a1 APTR msg)
  36. {
  37.     struct PopupMenu *pm=(struct PopupMenu *)object;
  38.  
  39.     printf("---\n");
  40.     printf("Title:      \"%s\"\n", pm->Title);
  41.     printf("UserData: %lx\n", pm->UserData);
  42.     printf("ID:      %lx\n", pm->ID);
  43.  
  44.     // This is one (the fastest) way of finding out if the item is checked or not:
  45.     // 0x40000000 = CHECKIT
  46.     // 0x80000000 = CHECKED
  47.     if(pm->Flags&0x40000000)
  48.         printf("Checked?  %s\n", pm->Flags&0x80000000?"Yes":"No");
  49.  
  50.     if((int)pm->UserData==5) *((BOOL *)hook->h_Data)=FALSE;
  51. }
  52.  
  53. struct PopupMenu *MakeTestMenu(void);
  54.  
  55. void main()
  56. {
  57.     BOOL r=TRUE;
  58.     struct IntuiMessage *im,imsg;
  59.     struct PopupMenu *p;
  60.     struct Hook MenuHandler;
  61.  
  62.     MenuHandler.h_Entry=(HOOKFUNC)MenuHandlerFunc;
  63.     MenuHandler.h_Data=&r;
  64.  
  65.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  66.     if(PopupMenuBase) {
  67.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  68.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  69.  
  70.         p=MakeTestMenu(); // Declared at the end of this file.
  71.  
  72.         if(p) {
  73.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY,    // Open a little window
  74.                     WA_RMBTrap,    TRUE,
  75.                     WA_DragBar,    TRUE,
  76.                     WA_Width,    150,
  77.                     WA_Height,    100,
  78.                     WA_Left,    0,
  79.                     WA_Top,        100,
  80.                     WA_Title,    "PullDown Menus",
  81.                     WA_CloseGadget,    TRUE,
  82.                     TAG_DONE);
  83.             if(w) {
  84.                 while(r) {
  85.                     WaitPort(w->UserPort);                        // Wait for a message
  86.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  87.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  88.                         ReplyMsg((struct Message *)im);                // Reply the message
  89.  
  90.                         PM_FilterIMsg(w, p, &imsg,                // Send the message to pmlib
  91.                             PM_AutoPullDown,    TRUE,            // We want the menu to open automatically
  92.                             PM_MenuHandler,        &MenuHandler,        // Our menuhandler function
  93.                             TAG_DONE);
  94.  
  95.                         if(imsg.Class==IDCMP_CLOSEWINDOW) r=FALSE;        // See if the user wants to quit
  96.                     }
  97.                 }
  98.                 CloseWindow(w);
  99.             } else printf("Window error!\n");
  100.             PM_FreePopupMenu(p);
  101.         } else printf("Menu error!\n");
  102.         CloseLibrary((struct Library *)PopupMenuBase);
  103.     }
  104. }
  105.  
  106. struct PopupMenu *MakeTestMenu()
  107. {
  108.     struct PopupMenu *p;
  109.  
  110.     p=PM_MakeMenu(
  111.         PMItem("Workbench"),
  112.             PMSimpleSub,
  113.                 PMCheckItem("Backdrop?", 1),        PM_CommKey,    "B",    End,
  114.                 PMItem("Execute Command..."),        PM_CommKey,    "E",    End,
  115.                 PMItem("Redraw All"),    End,
  116.                 PMItem("Update All"),    End,
  117.                 PMItem("Last Message"),    End,
  118.                 PMItem("About..."),    PM_BuiltInIcon,    PMIMG_ABOUT,    PM_CommKey,    "?",    End,
  119.                 PMItem("Quit"),        PM_BuiltInIcon,    PMIMG_QUIT,    PM_UserData,    5,    PM_CommKey,    "Q",    End,
  120.             End,
  121.         End,
  122.         PMItem("Window"),
  123.             PMSimpleSub,
  124.                 PMItem("New Drawer"),        PM_CommKey,    "N",    PM_Disabled,    TRUE,    End,
  125.                 PMItem("Open Parent"),                    PM_Disabled,    TRUE,    End,
  126.                 PMItem("Close"),        PM_CommKey,    "K",    PM_Disabled,    TRUE,    End,
  127.                 PMItem("Update"),                    PM_Disabled,    TRUE,    End,
  128.                 PMItem("Select Contents"),    PM_CommKey,    "A",                End,
  129.                 PMItem("Clean Up"),        PM_CommKey,    ".",                End,
  130.                 PMItem("Snapshot"),
  131.                     PMSimpleSub,
  132.                         PMItem("Window"),    End,
  133.                         PMItem("All"),        End,
  134.                     End,
  135.                 End,
  136.                 PMItem("Show"),
  137.                     PMSimpleSub,
  138.                         PMCheckItem("Only Icons", 2),    PM_Exclude,    PM_ExLst(3, 0),    PM_Checked,    TRUE,    End,
  139.                         PMCheckItem("All Files", 3),    PM_Exclude,    PM_ExLst(2, 0),    End,
  140.                     End,
  141.                     PM_Disabled,    TRUE,
  142.                     //PM_BuiltInIcon,    PMIMG_SHOW,
  143.                 End,
  144.                 PMItem("View By"),
  145.                     PMSimpleSub,
  146.                         PMCheckItem("Icon", 4),        PM_Exclude,    PM_ExLst(5, 6, 7, 0),    PM_Checked,    TRUE,    End,
  147.                         PMCheckItem("Name", 5),        PM_Exclude,    PM_ExLst(4, 6, 7, 0),    End,
  148.                         PMCheckItem("Date", 6),        PM_Exclude,    PM_ExLst(4, 5, 7, 0),    End,
  149.                         PMCheckItem("Size", 7),        PM_Exclude,    PM_ExLst(4, 5, 6, 0),    End,
  150.                     End,
  151.                     PM_Disabled,    FALSE,
  152.                 End,
  153.             End,
  154.         End,
  155.         PMItem("Icons"),
  156.             PMSimpleSub,
  157.                 PMItem("Open"),            PM_CommKey,    "O",    End,
  158.                 PMItem("Copy"),            PM_CommKey,    "C",    End,
  159.                 PMItem("Rename..."),        PM_CommKey,    "R",    End,
  160.                 PMItem("Information..."),    PM_CommKey,    "I",    End,
  161.                 PMItem("Snapshot"),        PM_CommKey,    "S",    End,
  162.                 PMItem("UnSnapshot"),        PM_CommKey,    "U",    End,
  163.                 PMItem("Leave Out"),        PM_CommKey,    "L",    End,
  164.                 PMItem("Put Away"),        PM_CommKey,    "P",    End,
  165.                 PMBar,                            End,
  166.                 PMItem("Delete..."),        PM_Disabled,    TRUE,    End,
  167.                 PMItem("FormatDisk..."),                End,
  168.                 PMItem("Empty Trash"),        PM_Disabled,    TRUE,    End,
  169.             End,
  170.         End,
  171.         PMItem("Tools"),
  172.             PMSimpleSub,
  173.                 PMItem("ResetWB"),    End,
  174.             End,
  175.         End,
  176.     End;
  177.  
  178.     return p;
  179. }